package com.solution.admin.customer.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.solution.admin.customer.dao.DeliveryAddressDao;
import com.solution.admin.customer.entity.DeliveryAddressEntity;
import com.solution.common.dao.impl.BaseDaoImpl;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

/**
 * 收货地址表DAO实现
 * @author solin
 * @date 2017-09-22 11:55:25
 */
@Repository
public class DeliveryAddressDaoImpl extends BaseDaoImpl<DeliveryAddressEntity> implements DeliveryAddressDao {
	@Autowired
	private SqlSessionTemplate sessionTemplate;
	
	/**
	 * 保存收货地址表信息
	 * @param deliveryAddressEntity
	 * @return
	 * @author solin
	 * @date 2017-09-22 11:55:25
	 */
	@Override
	public long saveDeliveryAddress(DeliveryAddressEntity deliveryAddressEntity) {
		return super.insert(deliveryAddressEntity);
	}

	/**
	 * 分页查询收货地址表信息
	 * @param pageParam 分页对象
	 * @param deliveryAddress 分页参数
	 * @return PageBean 分页参数及数据
	 * @author solin
	 * @date 2017-09-22 11:55:25
	 */
	public PageBean listDeliveryAddressPage(PageParam pageParam, Map<String, Object> param) {
		return super.listPage(pageParam, param);
	}

	/**
	 * 更新收货地址表
	 * @param deliveryAddressEntity
	 * @return
	 * @author solin
	 * @date 2017-09-22 11:55:25
	 */
	@Override
	public int updateDeliveryAddress(DeliveryAddressEntity deliveryAddressEntity) {
		return super.update(deliveryAddressEntity);
	}
	
	/**
	 * 根据客户ID修改收货地址表信息
	 * @param deliveryAddressEntity
	 * @return
	 * @author: solin
	 * @date: 2017年11月2日 上午12:47:11
	 */
	@Override
	public int updateByCustomerId(DeliveryAddressEntity deliveryAddressEntity){
		return this.sessionTemplate.update("updateByCustomerId", deliveryAddressEntity);
	}

	/**
	 * 删除收货地址表
	 * @param deliveryAddressId
	 * @return
	 * @author solin
	 * @date 2017-09-22 11:55:25
	 */
	public int deleteDeliveryAddressById( Long id) {
		return super.deleteById(id);
	}
	
	/**
	 * 根据条件查询收货地址表
	 * @param param
	 * @return
	 * @author solin
	 * @date 2017-09-22 11:55:25
	 */
	@Override
	public List<DeliveryAddressEntity> listDeliveryAddress( Map<String, Object> param) {
		return super.listBy(param);
	}

	/**
	 * 查询公司除该地址之外的其他地址id
	 * @param id
	 * @param companyId
	 * @return
	 * @author xkl
	 * @date 2018年3月23日 下午6:04:34
	 */
	@Override
	public List<Long> listOtherAddressIds(Long id, Long companyId) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("id", id);
		paramMap.put("companyId", companyId);
		return getSessionTemplate().selectList("listOtherAddressIds", paramMap);
	}
}
